/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import {
  getList
} from "@/services/complain";
import { message } from "antd";

export default {
  namespace: "complain",

  state: {
    list: {
      list: null,
      pagination: null,
    }
  },

  effects: {
    //获取驿站投诉列表
    *getList({ payload, __dva_resolve, __dva_reject }, { call, put }) {
      const response = yield call(getList, payload);
      if (!response) return;
      const { code, data, msg } = response;
      const { list, total, page } = data;
      if (code == 0) {
        yield put({
          type: "save",
          payload: {
            list: {
              list,
              pagination: {
                total,
                current: page,
                pageSize: 15,
                showQuickJumper: false,
                showSizeChanger: false,
              }
            },
          },
        });
        __dva_resolve(response);
      } else {
        __dva_reject(response);
        message.error(msg);
      }
    }
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
